using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;

namespace EditorExtensions
{
    public class AdvancedDropDownExample: EditorWindow
    {
        [MenuItem("EditorExtensions/10.AdvancedDropDown/Open")]
        static void Open()
        {
            CreateInstance<AdvancedDropDownExample>().Show();
        }

        private void OnGUI()
        {
            var rect = GUILayoutUtility.GetRect(new GUIContent("Show"), EditorStyles.toolbarButton);
            if(GUI.Button(rect, new GUIContent("Show"), EditorStyles.toolbarButton))
            {
                var dropDown = new WeekdaysDropdown(new AdvancedDropdownState());
                dropDown.Show(rect);
            }
        }

        public class WeekdaysDropdown : AdvancedDropdown
        {
            public WeekdaysDropdown(AdvancedDropdownState state) : base(state)
            {
            }

            protected override AdvancedDropdownItem BuildRoot()
            {
                var root = new AdvancedDropdownItem("Weekdays");
                var firstHalf = new AdvancedDropdownItem("First Half");
                firstHalf.AddChild(new AdvancedDropdownItem("1day"));
                firstHalf.AddChild(new AdvancedDropdownItem("2day"));
                var SecondHalf = new AdvancedDropdownItem("First Half");
                SecondHalf.AddChild(new AdvancedDropdownItem("3day"));
                SecondHalf.AddChild(new AdvancedDropdownItem("4day"));
                SecondHalf.AddChild(new AdvancedDropdownItem("5day"));
                var weekend = new AdvancedDropdownItem("Weekend");
                weekend.AddChild(new AdvancedDropdownItem("6day"));
                weekend.AddChild(new AdvancedDropdownItem("7day"));
                weekend.AddChild(new AdvancedDropdownItem("8day"));
                root.AddChild(firstHalf);
                root.AddChild(SecondHalf);
                root.AddChild(weekend);
                return root;
            }
        }
    }

}
